package com.wanjia.estate.service.bdservice.bdcdjxxcxjgzmservice;

import com.spire.xls.ExcelPicture;
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

//Excel表格添加图片
@Slf4j
@Service
public class ExcelAddImgBdcService {

    @Value("${sealpath}")
    private String sealpath;

    public String ExcelAddImg(String excelPath) throws IOException {

        //创建Workbook实例
        Workbook workbook = new Workbook();
        //加载Excel文档
        workbook.loadFromFile(excelPath);
        //获取第一张工作表
        Worksheet sheet = workbook.getWorksheets().get(0);

        //添加图片到工作表的指定位置
        ExcelPicture pic1 = sheet.getPictures().add(12, 4,sealpath);

        //设置图片的宽度和高度
        pic1.setWidth(150);
        pic1.setHeight(50);

        //保存文档
        workbook.saveToFile(excelPath, ExcelVersion.Version2013);

        return excelPath;
    }
}
